package com.xtayfjpk.zookeeper.test.master_workers.callback.client;

import org.apache.log4j.Logger;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.KeeperException.Code;

import com.xtayfjpk.zookeeper.test.master_workers.Client;
import com.xtayfjpk.zookeeper.test.master_workers.callback.BaseVoidCallback;

public class DeleteTaskResultCallback extends BaseVoidCallback {
	private static final Logger LOGGER = Logger.getLogger(DeleteTaskResultCallback.class);
	private Client client;
	public DeleteTaskResultCallback(Client client) {
		this.client = client;
	}
	
	
	@Override
	protected void connectionLossCaseAction(int rc, String path, Object ctx) {
		client.deleteTaskResult(path);
	}
	
	@Override
	protected void okCaseAction(int rc, String path, Object ctx) {
		LOGGER.info("Successfully deleted " + path);
		client.getCtxMap().remove(path);
	}
	
	@Override
	protected void defaultCaseAction(int rc, String path, Object ctx) {
		LOGGER.error("Something went wrong here, " + 
                KeeperException.create(Code.get(rc), path));
	}
}
